package com.huiquan.vocab.service;

import com.huiquan.dyad.dao.DyadStdDao;
import com.huiquan.dyad.domain.DyadPre;
import com.huiquan.dyad.service.DyadInitService;
import com.huiquan.foundation.constant.BusinessContants;
import com.huiquan.foundation.constant.CheckParamType;
import com.huiquan.foundation.service.CheckParamService;
import com.huiquan.foundation.util.BusinessUtil;
import com.huiquan.framework.base.BaseService;
import com.huiquan.framework.dao.EmailDao;
import com.huiquan.framework.utils.ArrayUtil;
import com.huiquan.framework.utils.CollectionUtil;
import com.huiquan.framework.utils.EMailUtil;
import com.huiquan.framework.utils.FileUtils;
import com.huiquan.management.constant.MigrateCode;
import com.huiquan.management.domain.Migrate;
import com.huiquan.management.service.MigrateService;
import com.huiquan.synonymy.dao.SynonymyWordDao;
import com.huiquan.vocab.constant.VocabConstant;
import com.huiquan.vocab.dao.VocabDyadDao;
import com.huiquan.vocab.dao.VocabDyadPositionDao;
import com.huiquan.vocab.dao.VocabElementDao;
import com.huiquan.vocab.domain.HiveSymptomDyadStd;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class VocabDyadSymptomService extends BaseService {

	@Autowired
	private VocabElementDao vocabElementDao;
	@Autowired
	private SynonymyWordDao synonymyWordDao;
	@Autowired
	private VocabDyadPositionDao vocabDyadPositionDao;
	@Autowired
	private VocabDyadDao vocabDyadDao;
	@Autowired
	private DyadInitService dyadInitService;
	@Autowired
	private DyadStdDao dyadStdDao;
	@Autowired
	private EMailUtil eMailUtil;
	@Autowired
	private EmailDao emailDao;
	@Autowired
	private MigrateService migrateService;

	@Value("${dyad.get.symptom.std.dyad.input.file.script}")
	private String inputFileScript;
	@Value("${dyad.get.symptom.std.dyad.input.file.path}")
	private String inputFilePath;

	private Map<String, String> elementReplaceMap = new HashMap<>();

	public void exportSymptomStdDyadTo181() {

		try {
			// 根据code获取迁移表数据
			Migrate migrate = migrateService.getMigrateByCode(MigrateCode.DYAD_SYMPTOM_RELATION_HIVE);

			BusinessUtil.excuteShell(new String[] { inputFileScript, migrate.getSource(), inputFilePath });

			SymptomStdResult stdResult = getStdResultByFile(inputFilePath, 1);

			// 导出时增加方位词判断---新增展现P字段
			getDisplayP(stdResult);

			// 先导出到本地，如果后面有异常也可以从该备份中查询
			String outputFilePath = migrateService.getBakFilePathByCode(MigrateCode.DYAD_SYMPTOM_RELATION_FILE, true);
			FileUtils.generateFile(outputFilePath, stdResult.getResult().toString());

			// 根据历史数据信息校验当前导出数据是否有异常
			if (checkData(stdResult.getResult().length(), stdResult.getResultNum(), stdResult.getResultStdNum())) { // 校验合格

				// 更新校验参数
				updateCheckParam(stdResult.getResult().length(), stdResult.getResultNum(), stdResult.getResultStdNum());

				// 将文件同步到181文件
				migrateService.migrateFileByCodeAndBak(MigrateCode.DYAD_SYMPTOM_RELATION_FILE, outputFilePath, true);

				// 将文件同步到181HIVE
				migrateService.migrateHiveByCodeAndBak(MigrateCode.DYAD_SYMPTOM_RELATION_HIVE, outputFilePath);

			} else {
				// 校验不合格则不更新文件，发送异常邮件
				List<String> address = emailDao.retrieveAddressList(BusinessContants.SEND_EMAIL_GROUP_DYAD_ERROR);
				String subject = "标注系统-" + CheckParamType.SYMPTOM_STD_DYAD_OUTPUT.getDesc() + "失败";

				if (!address.isEmpty()) {
					eMailUtil.sendBatchEmail("", subject, address);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			handleException(e, CheckParamType.SYMPTOM_STD_DYAD_OUTPUT.getDesc());
		}
	}

	/**
	 * 根据症状的二元组匹配展示的p
	 */
	private void getDisplayP(SymptomStdResult stdResult) {
		// 获取o同义词
		List<Map<String, String>> synOList = synonymyWordDao.retrieveElementSynonymO();
		Map<String, String> synO = new HashMap<>();
		for (Map<String, String> oStd : synOList) {
			synO.put(oStd.get("word"), oStd.get("std"));
		}
		// 获取p同义词
		List<Map<String, String>> synPList = synonymyWordDao.retrieveElementSynonymByProperty("p");
		Map<String, String> synP = new HashMap<>();
		for (Map<String, String> pStd : synPList) {
			synP.put(pStd.get("word"), pStd.get("std"));
		}
		// 获取展示的P
		// 先初始化再获取
		vocabDyadPositionDao.init();
		List<Map<String, String>> displayPList = vocabDyadPositionDao.retrieveDisplayP();
		Map<String, Map<String, String>> displayPMap = new HashMap<>();
		for (Map<String, String> temp : displayPList) {
			String oStd = temp.get("o_std");
			String p = temp.get("p").substring(1, temp.get("p").length() - 1);
			String displayFlag = temp.get("display_flag");
			if (displayPMap.get(oStd) != null) {
				displayPMap.get(oStd).put(p + "|" + temp.get("right_p"),
						temp.get("display_p").substring(1, temp.get("display_p").length() - 1) + "|" + displayFlag);
				if (synP.get(p) != null) {
					displayPMap.get(oStd).put(synP.get(p) + "|" + temp.get("right_p"),
							temp.get("display_p").substring(1, temp.get("display_p").length() - 1) + "|" + displayFlag);
				}
			} else {
				Map<String, String> tempMap = new HashMap<>();
				tempMap.put(p + "|" + temp.get("right_p"),
						temp.get("display_p").substring(1, temp.get("display_p").length() - 1) + "|" + displayFlag);
				if (synP.get(p) != null) {
					tempMap.put(synP.get(p) + "|" + temp.get("right_p"),
							temp.get("display_p").substring(1, temp.get("display_p").length() - 1) + "|" + displayFlag);
				}
				displayPMap.put(oStd, tempMap);
			}
		}

		String[] resultStr = stdResult.getResult().split("\n");
		StringBuffer rtnStr = new StringBuffer();
		for (String line : resultStr) {
			String[] valueArr = line.split((char) 1 + "");
			rtnStr.append(line).append((char) 1 + "");
			if (valueArr.length == 13) {
				String partPattern = valueArr[11];
				if (partPattern.indexOf(",p,") > -1
						&& (partPattern.indexOf(",o,") > -1 || partPattern.indexOf(",oa,") > -1)) {
					String array = valueArr[10].substring(1, valueArr[10].length() - 1);
					partPattern = partPattern.substring(1, partPattern.length() - 1);
					String[] arrayArr = array.split(",");
					String[] partPatternArr = partPattern.split(",");
					String p = "";
					String pStd = "";
					String o = "";
					String rightP = "0";
					for (int i = 0; i < arrayArr.length; i++) {
						if (StringUtils.equals(partPatternArr[i], "p")) {
							p += arrayArr[i];
							p += ",";
							pStd += synP.get(arrayArr[i]) != null ? synP.get(arrayArr[i]) : arrayArr[i];
							pStd += ",";
						} else if (StringUtils.equals(partPatternArr[i], "o")
								|| StringUtils.equals(partPatternArr[i], "oa")) {
							o += synO.get(arrayArr[i]) != null ? synO.get(arrayArr[i]) : arrayArr[i];
							if (i == 0) {
								rightP = "1";
							}
						}
					}
					p = p.substring(0, p.length() - 1);
					pStd = pStd.substring(0, pStd.length() - 1);
					String displayP = "";
					String displayFlag = "-1";
					if (displayPMap.get(o) != null) {
						Map<String, String> pAndDisplayP = displayPMap.get(o);
						if (pAndDisplayP.get(p + "|" + rightP) != null) {
							String[] displayPAndDisplayflag = pAndDisplayP.get(p + "|" + rightP).split("\\|");
							displayP = displayPAndDisplayflag[0];
							displayFlag = displayPAndDisplayflag[1];
						} else if (pAndDisplayP.get(pStd + "|" + rightP) != null) {
							String[] displayPAndDisplayflag = pAndDisplayP.get(pStd + "|" + rightP).split("\\|");
							displayP = displayPAndDisplayflag[0];
							displayFlag = displayPAndDisplayflag[1];
						}
					}
					rtnStr.append(displayP).append((char) 1 + "").append(displayFlag);
				} else {
					rtnStr.append((char) 1 + "").append("-1");
				}
			} else {
				rtnStr.append((char) 1 + "").append("-1");
			}
			rtnStr.append("\n");
		}
		stdResult.setResult(rtnStr.toString());
	}

	private void handleException(Exception e, String string) {
		LOGGER.error("Migrate error:" + string);

		// 报错后发邮件通知
		List<String> address = emailDao.retrieveAddressList(BusinessContants.SEND_EMAIL_GROUP_DATA_RUNNING_ERROR);
		String subject = "标注系统同步数据出错：" + string;
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		e.printStackTrace(new PrintStream(baos));
		String content = baos.toString();

		if (!address.isEmpty()) {
			try {
				eMailUtil.sendBatchEmail(content, subject, address);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}

		e.printStackTrace();
	}

	private SymptomStdResult getStdResultByFile(String path, int type) throws Exception {
		int resultNum = 0, resultStdNum = 0;
		StringBuffer result = new StringBuffer();

		File inputFile = new File(path);
		if (inputFile.exists()) {
			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile), "utf-8"));
			// 获取o和s同义词集合
			Map<String, Map<String, String>> synonymy = getSynonymyMap();
			Map<String, String> dyadStdMap = getDyadStdMap();
			// 忽略P的规则初始化
			/** 忽略P的规则. */
			Map<String, String> osIgnorePStd = getIgnorePMap();
			List<String> resultStd = new ArrayList<>();

			try {

				String line ;
				String symptom ;
				String symptomArray ;
				String partPattern ;
				String cnt ;
				List<HiveSymptomDyadStd> dyadStdList = new ArrayList<>();
				while ((line = br.readLine()) != null) {
					if (!line.isEmpty() && line.split("" + ((char) 1)).length > 2) {
						symptom = line.split("" + ((char) 1))[0];
						symptomArray = "," + line.split("" + ((char) 1))[1] + ",";
						partPattern = "," + line.split("" + ((char) 1))[2] + ",";
						cnt = line.split("" + ((char) 1))[3];
						List<String> arrayList = CollectionUtil.getListByArray(symptomArray.substring(1).split(","));
						List<String> propertyList = CollectionUtil.getListByArray(partPattern.substring(1).split(","));
						List<String> arrayStdList = new ArrayList<>();
						for (int i = 0; i < arrayList.size(); i++) {
							arrayStdList.add(synonymy.get(propertyList.get(i)).get(arrayList.get(i)) == null
									? arrayList.get(i) : synonymy.get(propertyList.get(i)).get(arrayList.get(i)));
						}
						// 用症状忽略p
						ignoreP(arrayStdList, propertyList, arrayList, osIgnorePStd);
						// 根据症状抽取二元组
						List<DyadPre> dyadList = dyadInitService.getDyadPreBySymptom(
								BusinessUtil.getStringFromListBySeparator(arrayList, ","),
								BusinessUtil.getStringFromListBySeparator(propertyList, ","));
						if (dyadList != null && dyadList.size() > 0) {
							for (DyadPre dyad : dyadList) {
								String dyadStd = dyadStdMap.get(dyad.getArray() + "|" + dyad.getPartPattern()) == null
										? dyad.getArray() + "|" + dyad.getPartPattern() + "|" + "-1"
										: dyadStdMap.get(dyad.getArray() + "|" + dyad.getPartPattern());
								String[] dyadStdArr = dyadStd.split("\\|");
								HiveSymptomDyadStd symptomDyadStd = new HiveSymptomDyadStd();
								symptomDyadStd.setCnt(cnt);
								symptomDyadStd.setSymptom(symptom);
								symptomDyadStd.setSymptomArray(symptomArray);
								symptomDyadStd.setPartPattern(partPattern);
								symptomDyadStd.setDyadStdArray(dyadStdArr[0]);
								symptomDyadStd.setDyadStdPartPattern(dyadStdArr[1]);
								symptomDyadStd.setDyadFlag(dyadStdArr[2]);
								symptomDyadStd.setDyadArray(dyad.getArray());
								symptomDyadStd.setDyadPartPattern(dyad.getPartPattern());
								dyadStdList.add(symptomDyadStd);
							}
						}
					}
				}
				// 清空临时表
				dyadStdDao.deleteAllSymptomDyadStd();
				// 批量插入临时表
				dyadStdDao.batchInsertSymptomDyadStd(dyadStdList);

				// 维护好症状标准词和二元组标准词, 所有二元组标准词都相同的症状视为该症状为同义词
				dyadStdDao.initSymptomDyadStd();

				// 取出维护好的症状标准词
				List<Map<String, String>> dyadList = dyadStdDao.retrieveSymptomDyadStd();
				for (Map<String, String> dyad : dyadList) {
					result.append(dyad.get("id"));
					result.append("" + ((char) 1));
					result.append(dyad.get("symptom"));
					result.append("" + ((char) 1));
					result.append(dyad.get("symptom_array"));
					result.append("" + ((char) 1));
					result.append(dyad.get("part_pattern"));
					result.append("" + ((char) 1));
					result.append(dyad.get("cnt"));
					result.append("" + ((char) 1));
					// 标准症状要忽略P
					List<String> arrayList = CollectionUtil
							.getListByArray(dyad.get("std_symptom_array").substring(1).split(","));
					List<String> propertyList = CollectionUtil
							.getListByArray(dyad.get("std_part_pattern").substring(1).split(","));
					List<String> arrayStdList = new ArrayList<>();
					for (int i = 0; i < arrayList.size(); i++) {
						arrayStdList.add(synonymy.get(propertyList.get(i)).get(arrayList.get(i)) == null
								? arrayList.get(i) : synonymy.get(propertyList.get(i)).get(arrayList.get(i)));
					}
					// 用症状忽略p
					ignoreP(arrayStdList, propertyList, arrayList, osIgnorePStd);
					result.append(BusinessUtil.getStringFromListBySeparator(arrayList, ""));
					result.append("" + ((char) 1));
					result.append(BusinessUtil.getStringFromListBySeparator(arrayList, ","));
					result.append("" + ((char) 1));
					result.append(BusinessUtil.getStringFromListBySeparator(propertyList, ","));
					result.append("" + ((char) 1));
					result.append(dyad.get("dyad_std_array"));
					result.append("" + ((char) 1));
					result.append(dyad.get("dyad_std_part_pattern"));
					result.append("" + ((char) 1));
					result.append(dyad.get("da"));
					result.append("" + ((char) 1));
					result.append(dyad.get("dp"));
					result.append("" + ((char) 1));
					result.append(dyad.get("status"));
					result.append("\n");
					if (!resultStd.contains(dyad.get("std_symptom") + dyad.get("std_part_pattern"))) {
						resultStdNum++;
						resultStd.add(dyad.get("std_symptom") + dyad.get("std_part_pattern"));
					}
					resultNum++;
				}
			} catch (Exception e) {
				LOGGER.error("生成症状标准词出错：" + e.getMessage());
				throw e;
			} finally {
				br.close();
			}
		}

		LOGGER.info("症状标准词生成成功！结果数量=" + resultNum);

		SymptomStdResult symptomStdResult = new SymptomStdResult();
		symptomStdResult.setResult(result.toString());
		symptomStdResult.setResultNum(resultNum);
		symptomStdResult.setResultStdNum(resultStdNum);

		return symptomStdResult;
	}

	private Map<String, String> getIgnorePMap() {
		List<Map<String, String>> oSIgnoreP = vocabDyadDao.retrieveOSIgnoreP();
		Map<String, String> osIgnorePStd = new HashMap<>();
		for (Map<String, String> map : oSIgnoreP) {
			osIgnorePStd.put(map.get("o") + map.get("s"), map.get("type"));
		}
		return osIgnorePStd;
	}

	/**
	 * 获取所有二元组,对应二元组的标准词
	 *
	 */
	private Map<String, String> getDyadStdMap() {
		List<Map<String, String>> dyadStdList = vocabDyadDao.retrieveDyadAndStd();
		Map<String, String> rtn = new HashMap<>();
		for (Map<String, String> dyadStd : dyadStdList) {
			rtn.put(dyadStd.get("array") + "|" + dyadStd.get("part_pattern"),
					dyadStd.get("array_std") + "|" + dyadStd.get("part_pattern_std") + "|" + dyadStd.get("flag"));
		}
		return rtn;
	}

	private Map<String, Map<String, String>> getSynonymyMap() {
		// 所有的同义词
		List<Map<String, String>> synonymys = synonymyWordDao.retrieveElementSynonymByProperty("");
		Map<String, Map<String, String>> synonymyMap = new HashMap<>();
		for (Map<String, String> synonymy : synonymys) {
			String property = synonymy.get("property");
			String word = synonymy.get("word");
			String std = synonymy.get("std");
			if (synonymyMap.get(property) != null) {
				synonymyMap.get(property).put(word, std);
			} else {
				Map<String, String> syn = new HashMap<>();
				syn.put(word, std);
				synonymyMap.put(property, syn);
			}
		}
		return synonymyMap;
	}

	// 单双左右的标准词，现在默认系统里的，以后这个功能上线则按新需求来
	String danStd = "一侧";
	String shuangStd1 = "双侧";
	String shuangStd2 = "双";
	String zuoStd = "左";
	String youStd = "右";

	private void ignoreP(List<String> stdArrayList, List<String> propertyList, List<String> arrayList,
						 Map<String, String> osIgnorePStd) {
		List<String> oTemp = new ArrayList<>();
		List<Integer> pIndexTemp = new ArrayList<>();

		// 是否忽略单双或左右，或者全部p忽略
		boolean danShuang = false;
		boolean zuoYou = false;
		boolean all = false;
		for (int i = 0; i < propertyList.size(); i++) {
			String property = propertyList.get(i);
			if (VocabConstant.ELEMENT_POSITION.equals(property)) {
				pIndexTemp.add(i);

			} else if (VocabConstant.ELEMENT_ORGAN.equals(property)
					|| VocabConstant.ELEMENT_ORGAN_ADITIONAL.equals(property)) {
				oTemp.add(stdArrayList.get(i));

			} else if (VocabConstant.ELEMENT_SYMPTOM.equals(property)) {
				for (String o : oTemp) {
					// 判断o+s是否在忽略列表中
					String os = o + stdArrayList.get(i);
					String type = osIgnorePStd.get(os);
					if ("1".equals(type)) {
						// 1) 左右单双方位词可以都忽略
						danShuang = true;
						zuoYou = true;
					} else if ("3".equals(type)) {
						// 3) 分单双不分左右，忽略左右
						zuoYou = true;
					} else if ("4".equals(type)) {
						// 4) 方位词都忽略
						all = true;
					}
				}
			}
		}

		if (!pIndexTemp.isEmpty()) {
			if (all) {
				for (int i = pIndexTemp.size() - 1; i >= 0; i--) {
					stdArrayList.remove(pIndexTemp.get(i).intValue());
					propertyList.remove(pIndexTemp.get(i).intValue());
					arrayList.remove(pIndexTemp.get(i).intValue());
				}
			} else {
				for (int i = pIndexTemp.size() - 1; i >= 0; i--) {
					String pTemp = stdArrayList.get(pIndexTemp.get(i).intValue());
					boolean isDan = danStd.equals(pTemp);
					boolean isShuang = shuangStd1.equals(pTemp) || shuangStd2.equals(pTemp);
					if (danShuang && (isDan || isShuang)) {
						stdArrayList.remove(pIndexTemp.get(i).intValue());
						propertyList.remove(pIndexTemp.get(i).intValue());
						arrayList.remove(pIndexTemp.get(i).intValue());
					}

					boolean isZuo = zuoStd.equals(pTemp);
					boolean isYou = youStd.equals(pTemp);
					if (zuoYou && (isZuo || isYou)) {
						stdArrayList.remove(pIndexTemp.get(i).intValue());
						propertyList.remove(pIndexTemp.get(i).intValue());
						arrayList.remove(pIndexTemp.get(i).intValue());
					}
				}
			}
		}
	}

	@Autowired
	private CheckParamService checkParamService;

	/**
	 * 更新校验参数
	 *
	 * @param length
	 * @param resultNum
	 * @param resultStdNum
	 */
	private void updateCheckParam(int length, int resultNum, int resultStdNum) {

		CheckParamType cpt = CheckParamType.SYMPTOM_STD_DYAD_OUTPUT;
		String checkParam = ArrayUtil.joinStringBySeparator(new Integer[] { length, resultNum, resultStdNum }, ",");

		checkParamService.updateParamByType(cpt, checkParam);
	}

	/**
	 * 校验导出数据的三个指标：字符串长度，结果行数，标准症状个数
	 *
	 * @param length
	 * @param resultNum
	 * @param resultStdNum
	 * @return
	 */
	private boolean checkData(int length, int resultNum, int resultStdNum) {

		int[] currentParam = new int[] { length, resultNum, resultStdNum };

		CheckParamType cpt = CheckParamType.SYMPTOM_STD_DYAD_OUTPUT;

		// 获取校验参数
		String checkParam = checkParamService.getParamByType(cpt);

		if (checkParam == null || checkParam.isEmpty()) {
			checkParam = ArrayUtil.joinStringBySeparator(new Integer[] { length, resultNum, resultStdNum }, ",");
			String desc = cpt.getDesc() + "：字符串长度，结果行数，标准症状个数";

			checkParamService.add(cpt, checkParam, desc);

			LOGGER.error(cpt.getDesc() + "参数为空，已初始化！");
			return true;
		}

		// 将校验参数拆分并校验
		String[] valueStr = checkParam.split(",");
		if (valueStr.length != 3 || !isNumericArray(valueStr)) {
			LOGGER.error(cpt.getDesc() + "参数格式错误，请校验！");

			return false;
		}

		String[] paramDesc = new String[] { "字符长度", "结果行数", "标准症状个数" };
		boolean flag = true;
		for (int i = 0; i < currentParam.length; i++) {
			int difference = Math.abs(currentParam[i] - Integer.valueOf(valueStr[i]));
			double percentage = difference / Double.valueOf(valueStr[i]);

			LOGGER.info(cpt.getDesc() + paramDesc[i] + "为" + currentParam[i]);
			LOGGER.info(cpt.getDesc() + paramDesc[i] + "差异为" + percentage);

			if (percentage > 0.3) {
				flag = false;
			}
		}

		if (flag) {
			return true;
		}

		return false;
	}

	private boolean isNumericArray(String[] vs) {
		for (String v : vs) {
			if (v.isEmpty() || !StringUtils.isNumeric(v)) {
				return false;
			}
		}
		return true;
	}

	/**
	 * 针对元素中存在的替换将症状中的分词进行替换
	 *
	 * @param symptomArray
	 * @param partPattern
	 * @return
	 */
	private String[] getReplaceElement(String symptomArray, String partPattern) {
		String[] vocabs = symptomArray.substring(1).split(",");
		String[] props = partPattern.substring(1).split(",");

		if (vocabs.length != props.length) {
			return null;
		}

		StringBuffer resultArray = new StringBuffer(",");
		StringBuffer resultPartPattern = new StringBuffer(",");
		String result;
		for (int i = 0; i < props.length; i++) {
			if ((result = elementReplaceMap.get(vocabs[i] + "\t" + props[i])) != null) {
				resultArray.append(result.split("\t")[0]);
				resultPartPattern.append(result.split("\t")[1]);
			} else {
				resultArray.append(vocabs[i]);
				resultPartPattern.append(props[i]);
			}

			resultArray.append(",");
			resultPartPattern.append(",");
		}
		return new String[] { resultArray.toString(), resultPartPattern.toString() };
	}

	private void initElementReplace() {

		elementReplaceMap = new HashMap<>();

		List<Map<String, String>> elementReplaceList = vocabElementDao.retrieveElementReplace();
		for (Map<String, String> temp : elementReplaceList) {
			elementReplaceMap.put(temp.get("original"), temp.get("result"));
		}
	}

	public void localGetSymptomStdDyadByBatch(String inputPath, String type) throws Exception {

		SymptomStdResult stdResult = getStdResultByFile(inputPath, Integer.parseInt(type));

		String outputFilePath = new File(inputPath).getParent() + "/symptom_std_dyad_out.txt";

		FileUtils.generateFile(outputFilePath, stdResult.getResult().toString());
	}

	class SymptomStdResult {
		private String result;
		private int resultNum;
		private int resultStdNum;

		public String getResult() {
			return result;
		}

		public void setResult(String result) {
			this.result = result;
		}

		public int getResultNum() {
			return resultNum;
		}

		public void setResultNum(int resultNum) {
			this.resultNum = resultNum;
		}

		public int getResultStdNum() {
			return resultStdNum;
		}

		public void setResultStdNum(int resultStdNum) {
			this.resultStdNum = resultStdNum;
		}

	}

}
